//
//  KIDUserModel.m
//  YYB
//
//  Created by JKSD on 2018/5/22.
//  Copyright © 2018年 Allen. All rights reserved.
//

#import "KIDUserModel.h"

@implementation KIDUserModel
+ (NSDictionary *)mj_replacedKeyFromPropertyName
{
    return @{@"ID": @"id"};
}

+(instancetype)saveWithKeyValues:(id)keyValues{
    KIDUserModel *model = [[KIDUserModel findAllObject] firstObject];
    
    if (!model) {
        model = [[KIDUserModel alloc]init];
        
    }
    NSArray *proNames = [KIDUserModel getProperties][@"name"];
    
    for (NSString *proName in proNames) {
        if([proName isEqualToString:@"id"]){
            id value = [keyValues valueForKey:@"ID"];
            if (value) {
                
                [model setValue:[keyValues valueForKey:@"id"] forKey:@"ID"];
            }
        }
        id value = [keyValues valueForKey:proName];
        if (value) {
            
            [model setValue:[keyValues valueForKey:proName] forKey:proName];
        }
    }
    [model saveOrUpdate];
    return model;
}

+(NSString *)currentUserID{
    
    KIDUserModel *user = [[KIDUserModel findAllObject] firstObject];
    if(user.ID == nil)return @"";
    
    return user.ID;
}
+(NSString *)currentUserCount{
    
    KIDUserModel *user = [[KIDUserModel findAllObject] firstObject];
    if(user.loginAccount == nil)return @"";
    
    return user.loginAccount;
}
- (NSString *)userId
{
    if(_ID == nil)
    {
        _ID = @"";
    }
    return _ID;
}

+(instancetype)currentUser{
    
    KIDUserModel *user = [[KIDUserModel findAllObject] firstObject];
    
    return user;
}

+(BOOL)isLogin{
    
    if ([KIDUserModel currentUserCount].length > 0)  {
        return YES;
    }
    return NO;
}
@end
